<?php

namespace App\Console\Commands\WorkOrder;

use App\Models\Common\ResourcesModel;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class RefreshErrorResourceImg extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'workOrder:RefreshErrorResourceImg';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '刷新资源图片';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        ResourcesModel::query()
                      ->where("module", "WORK_ORDER")->where("business", "FUNCTION_OPEN")
                      ->where("name", "evaluationScreenshot")
                      ->get()->each(function (ResourcesModel $resourcesModel) {
                if (Str::startsWith($resourcesModel->url, "https://file.51kuafu.com/")) {
                    $resourcesModel->url = str_replace("https://file.51kuafu.com/", "", $resourcesModel->url);
                    $resourcesModel->save();
                }
            });
        return 0;
    }
}
